  <?php
/**
 * @package		Joomla.Site
 * @subpackage	Templates.beez5
 * @copyright	Copyright (C) 2005 - 2009 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */
// no direct access
defined('_JEXEC') or die;
$app = JFactory::getApplication();
$templateparams = $app->getTemplate(true)->params;

//evtl. ersetzen durch JPATH_COMPONENT.'/views/...'
// If the page class is defined, add to class as suffix.
// It will be a separate class if the user starts it with a space

require_once(JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php');

?>
<?php
JRequest::setVar('limit', JRequest::getVar('limit', 7, '', 'int'));
JRequest::setVar('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
jimport('joomla.html.pagination');
$catid = JRequest::getInt('id');
$lang =& JFactory::getLanguage();
$langdefault = $lang->getTag();

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__categories');
$query->where("parent_id='".$catid."'");   //put your condition here                            
$db->setQuery($query);
if ($db->getErrorNum()) {
    echo $db->getErrorMsg();
    exit;
}
$arr = $db->loadObjectList();
$total = count($arr);
$pagination = new JPagination($total, JRequest::getVar('limitstart'), JRequest::getVar('limit'));
$query->where("parent_id='".$catid."' LIMIT " . $pagination->limitstart . ", " . $pagination->limit . "");   //put your condition here
$db->setQuery($query);

$arr = $db->loadObjectList();
if(count($arr)){
foreach ($arr as $obj) {    
     $item->slug = $obj->alias ? ($obj->id.':'.$obj->alias) : $obj->id;    
    ?> 
                <div class="Group_Product">
                    <div class="Group_Name"><a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->slug))?>"><?php echo $obj->title;?></a></div>
                    <ul class="ItemProducts">
                                <?php
                                //show products in category
                                $db = JFactory::getDBO();
                                $query = $db->getQuery(true);
                                $query->select('*');
                                $query->from('#__content');
                                $query->where("catid='".$obj->id."'");   //put your condition here                            
                                $db->setQuery($query);
                                if ($db->getErrorNum()) {
                                    echo $db->getErrorMsg();
                                    exit;
                                }
                                $arrproduct = $db->loadObjectList();
                          if($arrproduct){
                                foreach($arrproduct as $objproduct)
                                {           
                                    $images = json_decode($objproduct->images);
                                ?> 
                                    <li class="">
                                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($objproduct->id,$objproduct->catid));?>" class="title_product"><?php echo $objproduct->title; ?> </a>
                                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($objproduct->id,$objproduct->catid));?>">
                                         <?php  if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
				<?php $imgfloat =  $images->float_intro; ?>
				
					<img
					
					echo 'class="caption"'.' title="<?php echo trim(stripslashes(strip_tags($objproduct->introtext)));?>"';
		
						src="<?php echo htmlspecialchars($images->image_intro); ?>"
						alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"
						width="235" />
				
				<?php endif; ?>    
                                        </a>
                                        <div class="detail_product_index"><?php echo trim_text($objproduct->introtext,40); ?> </div>
                                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($objproduct->id,$objproduct->catid));?>" class="xemchitiet_product_index"><?php echo JText::_('VIEWDETAILS');?></a></li>
                          <?php }}else{ ?>                            
                                    <span class="nodata"><?php echo JText::_('NODATA');?></span>      
                          <?php } ?> 
                    </ul>
                </div>
<?php }}else{ ?> 
        <div class="Group_Product">Đang cập nhật dữ liệu</div>
<?php } ?> 

